#include "Key.h"
#include <vector>
#include <string.h>
#include <iostream>
#include <boost/foreach.hpp>

using namespace std;

void test_key(){
	CKey key;
	key.MakeNewKey(false);

	vector<unsigned char> vec_sig;
	char* p = "hello world";	
	uint256 hash = Hash(p, p + strlen(p));
	key.Sign(hash, vec_sig);

	vector<unsigned char> vec_compact_sig;
	key.SignCompact(hash, vec_compact_sig);

	cout << "Sig size: " << vec_sig.size() << endl;
	cout << "Sig:" << endl;
	BOOST_FOREACH(const unsigned char& tmp, vec_sig)
	{
		printf("%02x ", tmp);
	}
	cout << endl;
	cout << "Compact Sig Size: " << vec_compact_sig.size() << endl;
	cout << "Compact Sig:" << endl;
	BOOST_FOREACH(const unsigned char& tmp, vec_compact_sig)
	{
		printf("%02x ", tmp);
	}
	cout << endl;

	bool compact = false;
	CSecret secret;
	secret = key.GetSecret(compact);
	cout << "Secret Size: " << secret.size() << " Compressed: " << compact << endl;
	cout << "Secret:" << endl;
	BOOST_FOREACH(const unsigned char& tmp, secret)
	{
		printf("%02x ", tmp);
	}
	cout << endl;
	
	CPrivKey priv_key;
	priv_key = key.GetPrivKey();
	cout << "Privkey Size: " << priv_key.size() << endl;
	cout << "Privkey:" << endl;
	BOOST_FOREACH(const unsigned char& tmp, priv_key)
	{
		printf("%02x ", tmp);
	}
	cout << endl;

	key.SetCompressedPubKey(true);

	secret = key.GetSecret(compact);
	cout << "Secret Size: " << secret.size() << " Compressed: " << compact << endl;
	cout << "Secret:" << endl;
	BOOST_FOREACH(const unsigned char& tmp, secret)
	{
		printf("%02x ", tmp);
	}
	cout << endl;

	priv_key = key.GetPrivKey();
	cout << "Privkey Size: " << priv_key.size() << endl;
	cout << "Privkey:" << endl;
	BOOST_FOREACH(const unsigned char& tmp, priv_key)
	{
		printf("%02x ", tmp);
	}
	cout << endl;
}


int main(int argc, char* argv[]){
	test_key();
	return 0;
}
